<script src="//res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
<style>
  html {
    background: #f5f6f9;
  }
</style>
<div id="app" v-cloak>
  <div style="background-image: url(/img/bg.png); background-size: cover; padding-bottom: 100px"
    class="relative white p2 pt3 mb4">
    <div class="flex items-center">
      <!-- <img class="rounded" v-bind:src="client.avatar" style="width: 60px; height: 60px" /> -->

      <div style="flex: 1">
        <div class="font-18 bold px1 truncate" style="max-width: 160px">{{client.name}}</div>

        <div class="">
          <div class="px1 font-13">付费群 <span class="yellow">{{client.vip_num || 0}}</span> 个</div>
          <div class="px1 font-13">红包余额<span class="yellow"> {{client.red_money || 0}}</span>元</div>
        </div>
      </div>

      <div class="center">
        <a href="/client/charges" class="white font-13 underline">缴费记录</a>
        <div @click="showRedCharge=true" class="border border-white mt1 px2"
          style="border-radius: 15px; border-width: 2px">
          去充值
        </div>
      </div>
    </div>
  </div>

  <div class="flex font-13 shadow rounded2 relative z2 bg-white center py2 m2"
    style="justify-content: space-around; margin-top: -120px">
    <a href="/client/page/sendlist">
      <img src="/img/icons/send.svg" style="width: 40px; height: 40px" />
      <div class="p1 black bold">群发任务</div>
    </a>

    <a href="/client/users">
      <img src="/img/icons/jifen_icon.png" style="width: 40px; height: 40px" />

      <div class="py1 black bold">用户积分</div>
    </a>

    <a href="/client/pointOrders">
      <img src="/img/icons/order_icon.png" style="width: 40px; height: 40px" />

      <div class="py1 black bold">兑换记录</div>
    </a>

    <a href="/client/charges">
      <img src="/img/icons/charge_icon.png" style="width: 40px; height: 40px" />
      <div class="py1 black bold">缴费记录</div>
    </a>
  </div>
  <!-- <div class="my1 font-12 center" style="
				background: rgb(255, 241, 228);
				color: rgb(187, 100, 67);
				padding: 3px;
			">
			将机器人拉入群聊后， 即可出现在下方列表，付费即可使用
		</div> -->

  <div class="p1">
    <div style="border-left: 3px solid #368dff" class="px2 bold font-13">接入群聊</div>
    <div class="rounded2 bg-white shadow m1 p1">
      <div class="flex items-center p1" style="border-bottom: 1px solid #eef1ef" v-for="room in rooms">
        <div style="flex: 1" @click="openCharge(room)">
          <div class="font-14 bold">
            <div class="items-center flex">
              <svg t="1628230953594" class="icon" viewBox="0 0 1024 1024" version="1.1"
                xmlns="http://www.w3.org/2000/svg" p-id="7729" width="20" height="20">
                <path
                  d="M488.268351 107.789474C272.869053 107.789474 98.807018 258.245614 98.807018 443.984842c0 113.897544 66.52407 215.255579 166.947929 277.180632v103.944982c0 14.102456 10.024421 22.45614 21.324351 22.45614 4.185825 0 8.389614-1.293474 11.29993-2.89235l106.244491-70.242807c26.803649 5.748772 53.930667 7.042246 82.02779 7.042245 215.07593 0 389.461333-150.45614 389.461333-336.195368C877.388351 258.245614 703.326316 107.789474 488.250386 107.789474z m0 617.543859c-24.234667 0-48.128-2.874386-72.344702-7.06021l-11.29993-2.874386c-7.114105-1.293474-14.210246 0-21.306386 4.167859l-10.024421 7.042246-51.020351 33.684211v-54.846878c0-9.952561-5.802667-19.581754-14.19228-24.072982l-14.228211-8.335719c-87.848421-51.972491-140.144281-137.934596-140.144281-227.759158 0-154.624 148.55186-279.749614 332.620351-279.749614s332.620351 125.125614 332.620351 279.749614c1.940211 153.330526-148.228491 280.055018-330.68014 280.055017z m395.587368-198.889544c-0.970105-0.970105-1.616842-1.940211-2.586947-3.215719a315.912982 315.912982 0 0 1-25.833544 66.092912c0.323368 0.95214 0.970105 1.922246 1.616842 2.874386 7.419509 17.012772 11.29993 35.301053 11.29993 54.218106 0 50.696982-29.390596 98.807018-78.794105 128l-8.084211 4.814596c-4.850526 2.245614-8.066246 8.012351-8.066245 13.473684v30.79186l-28.74386-18.917053-5.479298-3.862456c-3.880421-2.245614-8.084211-3.197754-11.946667-2.245614l-6.467368 1.616842c-13.563509 2.568982-27.127018 3.844491-40.690527 3.844492-32.282947 0-62.967018-7.060211-89.465263-19.581755-26.462316 6.10807-53.912702 9.952561-82.009824 11.246035 44.247579 37.85207 105.274386 61.260351 172.463157 61.260351 17.749333 0 34.85193-0.95214 51.649123-4.491228l66.847439 44.283509c1.616842 0.95214 4.527158 1.598877 7.114105 1.598877 7.09614 0 13.24014-5.461333 13.24014-14.120421v-65.446175c63.290386-38.804211 105.274386-102.651509 105.274386-174.18779 0.323368-43.636772-15.180351-84.363228-41.337263-118.047439z"
                  fill="#0C67F6" p-id="7730"></path>
                <path
                  d="M314.206316 407.426246a46.708772 46.708772 0 0 1 46.816561 46.511158 46.708772 46.708772 0 0 1-46.816561 46.529122 46.708772 46.708772 0 0 1-46.834527-46.529122c0-25.67186 20.659649-46.529123 46.834527-46.529123z m176.954386 0a46.708772 46.708772 0 0 1 46.834526 46.511158 46.708772 46.708772 0 0 1-46.834526 46.529122 46.708772 46.708772 0 0 1-46.816562-46.529122 46.708772 46.708772 0 0 1 46.816562-46.529123z m171.169684 0a46.708772 46.708772 0 0 1 46.816561 46.511158 46.708772 46.708772 0 0 1-46.816561 46.529122 46.708772 46.708772 0 0 1-46.834526-46.529122 46.708772 46.708772 0 0 1 46.834526-46.529123z"
                  fill="#FF8C1B" p-id="7731"></path>
              </svg>
              <div class="pr1 underline bold">{{room.topic}}</div>
              <div class="gray normal font-12">{{room.memberIdList.length}}人</div>
            </div>
          </div>
          <div class="flex items-center orange font-12 pt1 bold">
            <!-- <div v-if="!room.pointRule" class="mr1 bg-red white px1">未开启积分</div> -->
            <div class="mr1 bg-orange white px1" v-if="room.pointRule && room.pointRule.sign_status">
              签 {{room.pointRule.sign_point}}
            </div>
            <div class="mr1 bg-blue white px1" v-if="room.pointRule && room.pointRule.invite_status">
              邀 {{room.pointRule.invite_point}}
            </div>
            <div v-if="room.vip" class="mr1 bg-green white px1">{{room.vip?'续 '+room.expiresDate:'未开通'}}</div>
          </div>
          <!-- <div class="gray bold font-12">
            <span class="mr1 bold underline red" @click="removeRoom(room)">移除</span>
            {{room.vip?'到期时间 '+room.expiresDate:'未开通'}}
            <span class="blue bold underline" v-if="room.vip" @click="openCharge(room)">续期</span>
          </div> -->
        </div>
        <div class="flex items-center p1">
          <div v-if="room.vip" class="weui-btn weui-btn_mini weui-btn_default" style="color: #368dff"
            @click="openPointRule(room)">
            设置
          </div>
          <div v-else class="weui-btn weui-btn_mini weui-btn_default" @click="openCharge(room)">
            {{room.vip?'续期':'开通'}}
          </div>
        </div>
      </div>
      <div class="font-12 p1 center gray">共 {{rooms.length}} 个群聊</div>
    </div>
  </div>

  <!-- 兑换码开通 -->
  <div v-show="showRedeem">
    <div class="weui-mask" @click="showRedeem = false"></div>
    <div class="weui-half-screen-dialog">
      <div class="weui-half-screen-dialog__hd">
        <div class="weui-half-screen-dialog__hd__main">
          <strong class="weui-half-screen-dialog__title"> {{selectedRoom.topic}} </strong>
        </div>
      </div>
      <div class="weui-half-screen-dialog__bd">
        <div class="bold font-15 pb1" v-if="selectedRoom.vip">到期时间：{{selectedRoom.expiresDate}}</div>
        <div class="weui-cells">
          <div class="weui-cell">
            <div class="weui-cell__hd">
              <label class="weui-label">兑换码</label>
            </div>
            <div class="weui-cell__bd">
              <input v-model="selectedRedeemCode" class="weui-input" placeholder="输入兑换码兑换" />
            </div>
          </div>
        </div>
      </div>
      <div class="weui-half-screen-dialog__ft">
        <div class="weui-btn weui-btn_primary" @click="redeemRoom">兑换</div>
      </div>
    </div>
  </div>
  <!-- 支付开通 -->
  <div v-show="showCharge">
    <div class="weui-mask" @click="showCharge = false"></div>
    <div class="weui-half-screen-dialog">
      <div class="weui-half-screen-dialog__hd">
        <div class="weui-half-screen-dialog__hd__main">
          <strong class="weui-half-screen-dialog__title">
            {{selectedRoom.topic}}

            <a href="javascript:void(0)" class="mr1 font-14 bold underline red" @click="removeRoom(selectedRoom)">移除</a>
          </strong>
        </div>
        <div class="weui-half-screen-dialog__hd__side">
          <a href="javascript:void(0)" @click="openRedeem(selectedRoom)" class="blue underline bold font-16">兑换码兑换</a>
        </div>
      </div>
      <div class="weui-half-screen-dialog__bd">
        <div class="bold font-15 pb1" v-if="selectedRoom.vip">到期时间：{{selectedRoom.expiresDate}}</div>

        <div v-if="!client.tryed && <%=process.env.TRY%>" class="center">
          <div style="text-decoration: line-through">
            ¥<span class="orange font-16 bold">
              <%=process.env.MONTHCHARGE%>
            </span>/<%=process.env.CHARGEDAYS%>天
          </div>
          <div class="px1"><span class="orange font-16 bold">免费</span>/<%=process.env.TRY%>天</div>
        </div>

        <div v-else>¥<span class="orange font-16 bold">
            <%=process.env.MONTHCHARGE%>
          </span>/<%=process.env.CHARGEDAYS%>天</div>
      </div>
      <div class="weui-half-screen-dialog__ft">
        <div v-if="!client.tryed  && <%=process.env.TRY%>" class="weui-btn weui-btn_primary" @click="tryRoom">
          免费体验
        </div>
        <div v-else class="weui-btn weui-btn_primary" @click="chargeRoom">支付</div>
      </div>
    </div>
  </div>

  <!-- 积分规则设置 -->
  <div v-show="showPointRule">
    <div class="weui-mask" @click="showPointRule=false"></div>
    <div class="weui-half-screen-dialog">
      <div class="weui-half-screen-dialog__hd">
        <div class="weui-half-screen-dialog__hd__main">
          <strong class="weui-half-screen-dialog__title"> 群聊积分规则设置 </strong>
        </div>

        <div class="weui-half-screen-dialog__hd__side">
          <a href="/client/page/setting" class="blue font-14 bold underline">全局话术设置</a>
        </div>
      </div>

      <div class="weui-half-screen-dialog__bd">
        <div class="flex items-center centent-start">
          <div class="btn btn-outline btn-small" v-bind:class="{'is-disabled': selectRuleLabel!='邀请'}"
            @click="selectRuleLabel = '邀请'">
            邀请
          </div>
          <div class="pr1"></div>
          <div v-bind:class="{'is-disabled': selectRuleLabel !='签到'}" class="btn btn-outline btn-small"
            @click="selectRuleLabel = '签到'">
            签到
          </div>
          <div class="pr1"></div>
          <div v-bind:class="{'is-disabled': selectRuleLabel !='欢迎语'}" class="btn btn-outline btn-small"
            @click="selectRuleLabel = '欢迎语'">
            欢迎语
          </div>
        </div>

        <div v-if="selectRuleLabel == '邀请'">
          <div class="weui-cells__title">邀请设置</div>
          <div class="weui-cells">
            <div class="weui-cell weui-cell_switch">
              <div class="weui-cell__bd">开启邀请积分功能</div>
              <div class="weui-cell__ft">
                <label class="weui-switch-cp">
                  <input class="weui-switch-cp__input" type="checkbox" v-model="selectedRule.invite_status" name="" />
                  <div class="weui-switch-cp__box"></div>
                </label>
              </div>
            </div>

            <div class="weui-cell weui-cell_switch">
              <div class="weui-cell__bd">开启邀请话术通知</div>
              <div class="weui-cell__ft">
                <label class="weui-switch-cp">
                  <input class="weui-switch-cp__input" type="checkbox" v-model="selectedRule.invite_notify" name="" />
                  <div class="weui-switch-cp__box"></div>
                </label>
              </div>
            </div>

            <div class="weui-cell">
              <div class="weui-cell__hd">
                <label class="weui-label">每邀请一人</label>
              </div>
              <div class="weui-cell__bd">
                <input v-model="selectedRule.invite_point" class="weui-input" placeholder="输入邀请积分" />
              </div>
              <div class="weui-cell__ft">
                <div>分</div>
              </div>
            </div>
          </div>
        </div>

        <div v-if="selectRuleLabel == '欢迎语'">
          <div class="weui-cells__title">欢迎语</div>
          <div class="weui-cells">
            <div class="weui-cell">
              <div class="weui-cell__bd">
                <textarea rows="4" class="weui-textarea" v-model="selectedRule.welcome" placeholder="设定群欢迎语"></textarea>
              </div>
            </div>
          </div>
        </div>

        <div v-if="selectRuleLabel == '签到'">
          <div class="weui-cells__title">签到设置</div>
          <div class="weui-cells">
            <div class="weui-cell weui-cell_switch">
              <div class="weui-cell__bd">开启签到积分功能</div>
              <div class="weui-cell__ft">
                <label class="weui-switch-cp">
                  <input class="weui-switch-cp__input" type="checkbox" v-model="selectedRule.sign_status" name="" />
                  <div class="weui-switch-cp__box"></div>
                </label>
              </div>
            </div>
            <div class="weui-cell weui-cell_switch">
              <div class="weui-cell__bd">开启签到话术通知</div>
              <div class="weui-cell__ft">
                <label class="weui-switch-cp">
                  <input class="weui-switch-cp__input" type="checkbox" v-model="selectedRule.sign_notify" name="" />
                  <div class="weui-switch-cp__box"></div>
                </label>
              </div>
            </div>

            <div class="weui-cell">
              <div class="weui-cell__hd">
                <label class="weui-label">每日签到</label>
              </div>
              <div class="weui-cell__bd">
                <input v-model="selectedRule.sign_point" class="weui-input" placeholder="输入签到积分" />
              </div>
              <div class="weui-cell__ft">
                <div>分</div>
              </div>
            </div>

            <div class="weui-cell">
              <div class="weui-cell__hd">
                <label class="weui-label">签到关键字</label>
              </div>
              <div class="weui-cell__bd">
                <input v-model="selectedRule.sign_word" class="weui-input" placeholder='默认"签到"' />
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="weui-half-screen-dialog__ft">
        <button @click="submitPointRule" class="weui-btn weui-btn_primary">提交</button>
      </div>
    </div>
  </div>
  <!-- 聊天群  -->

  <div class="p1">
    <div style="border-left: 3px solid #368dff" class="mt2 px2 bold font-13">积分奖励</div>

    <div class="shadow m1 bg-white p1 rounded2">
      <div class="flex items-center content-start">
        <div class="font-13 bold p1">兑换模式:</div>
        <div style="flex: 1" class="flex items-center centent-start">
          <div class="btn btn-small"
            v-bind:class="{'is-disabled': (client.home.label=='积分商城' || client.home.label=='积分抽奖' ),  'btn-outline': (client.home.label=='积分商城' || client.home.label=='积分抽奖' ), 'btn-primary': (client.home.label!='积分商城' && client.home.label!='积分抽奖') }"
            @click="setHome('red')">
            红包
          </div>
          <div class="p1"></div>
          <div
            v-bind:class="{'is-disabled': client.home.label!='积分商城' ,'btn-outline': client.home.label!='积分商城', 'btn-primary': client.home.label=='积分商城'}"
            class="btn btn-small" @click="setHome('mall')">
            商城
          </div>
          <div class="p1"></div>
          <div
            v-bind:class="{'is-disabled': client.home.label!='积分抽奖' ,'btn-outline': client.home.label!='积分抽奖', 'btn-primary': client.home.label=='积分抽奖'}"
            class="btn btn-small" @click="setHome('draw')">
            抽奖
          </div>
        </div>
        <div @click="showUserHome=true" class="blue bold">查看</div>
      </div>
    </div>

    <!-- <div class="weui-cells">
			<div class="weui-cell weui-cell_access" @click="selectHome">
				<div class="weui-cell__bd">兑换地址</div>
				<div class="weui-cell__ft">{{client.home?client.home.label:'积分商城'}}</div>
			</div>
		</div> -->

    <!-- <div class="weui-cells__title">兑换奖励</div> -->

    <div class="shadow m1 py1 bg-white rounded2" v-if="client.home.label!='积分抽奖'">
      <div class="p1 m1 font-13 bold flex">
        <div style="flex: 1">奖励商品</div>
        <a v-if="client.home.label=='积分商城'" class="blue bold underline" href="/client/page/item">创建奖励</a>
      </div>
      <div class="weui-cells">
        <a class="weui-cell weui-cell_active weui-cell_access" v-for="item in items"
          v-if="client.home.label=='积分商城' || client.home.value == item._id" v-bind:href="'/client/page/item/'+item._id">
          <div class="weui-cell__hd">
            <img v-bind:src="item.photo" style="width: 30px; height: 30px" />
          </div>
          <div class="weui-cell__bd mx1">
            <div class="font-13 bold">{{item.name}}</div>
            <div class="font-12">库存: {{item.stock}}</div>
          </div>
          <div class="weui-cell__ft font-13">{{item.point}}积分</div>
        </a>
      </div>
      <div class="p1 font-12 center gray" v-if="client.home.label=='积分商城'">共{{items.length}}个商品</div>
    </div>

    <div class="shadow m1 py1 bg-white rounded2" v-if="client.home.label=='积分抽奖'">
      <div class="p1 m1 font-13 bold flex">
        <div style="flex: 1">抽奖活动</div>
        <a class="blue bold underline" href="/client/page/item">新的抽奖</a>
      </div>
      <div class="weui-cells">
        <a class="weui-cell weui-cell_active weui-cell_access" v-for="draw in draws"
          v-bind:href="'/client/page/draw/'+draw._id">
          <div class="weui-cell__hd">
            <img v-bind:src="draw.photo" style="width: 100px; height: 50px" />
          </div>
          <div class="weui-cell__bd mx1">
            <div class="font-13 bold">{{draw.name}}</div>
            <div class="font-12">开奖时间: {{draw.opentime|timestr}} 开 {{draw.stock}} 个</div>
          </div>
          <div class="weui-cell__ft font-13">{{draw.point}}积分</div>
        </a>
      </div>
    </div>

  </div>

  <!-- <div class="center gray p2">到底了~</div> -->

  <!-- <div
			class="my1 font-12 center"
			style="
				background: rgb(255, 241, 228);
				color: rgb(187, 100, 67);
				padding: 3px;
			"
		>
			兑换地址会在签到和邀请积分时自动带出
		</div>
		 -->

  <div v-show="showUserHome">
    <div class="weui-mask" @click="showUserHome = false"></div>
    <div class="weui-half-screen-dialog">
      <div class="weui-half-screen-dialog__bd">
        <div class="center gray font-14 m1 p1">长按复制兑换地址</div>
        <div class="m1 p1 center bg-silver">
          <%=shorturl%>
        </div>
        <div class="center gray font-12 m1 p1">可用于群欢迎语, 朋友圈, 公众号推广等</div>
      </div>
      <div class="weui-half-screen-dialog__ft">
        <a class="weui-btn weui-btn_primary" v-bind:href="'/user/client/'+clientid">马上进入</a>
      </div>
    </div>
  </div>
  <div v-show="showRedCharge">
    <div class="weui-mask" @click="showRedCharge = false"></div>
    <div class="weui-half-screen-dialog">
      <div class="weui-half-screen-dialog__hd">
        <div class="weui-half-screen-dialog__hd__main">
          <strong class="weui-half-screen-dialog__title"> 红包充值 </strong>
        </div>
      </div>
      <div class="weui-half-screen-dialog__bd">
        <div class="weui-cells__title">红包充值扣除<%=process.env.REDFEE%>%手续费</div>
        <div class="weui-cells">
          <div class="weui-cell">
            <div class="weui-cell__hd">
              <label class="weui-label">充值金额</label>
            </div>
            <div class="weui-cell__bd">
              <input class="weui-input" type="number" placeholder="输入充值金额(元)" v-model="selectedRedMoney" />
            </div>
          </div>
        </div>
      </div>
      <div class="weui-half-screen-dialog__ft">
        <div class="weui-btn weui-btn_primary" @click="chargeRed">充值</div>
      </div>
    </div>
  </div>
</div>
<script>
  setTimeout(() => {
    if (app && app.clientid && app.client && app.client.name) {
      return
    }
    location.reload()
  }, 3000);
</script>
<script>
  wx.config({
    debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
    appId: '<%=process.env.FUWUHAOID%>', // 必填，公众号的唯一标识
    timestamp: <%=jsapi.timestamp %>, // 必填，生成签名的时间戳
    nonceStr: '<%=jsapi.noncestr%>', // 必填，生成签名的随机串
    signature: '<%=jsapi.sign%>',// 必填，签名
    jsApiList: ['chooseWXPay'] // 必填，需要使用的JS接口列表
  });
</script>

<script type="text/javascript">
  var app = new Vue({
    el: "#app",
    data: function () {
      return {
        // tab: "rooms",
        tab: "rooms",
        selectRuleLabel: "邀请",
        client: { home: {} },
        rooms: [],
        items: [],
        draws: [],
        showCharge: false,
        showRedeem: false,
        selectedRedeemCode: "",
        showUserHome: false,
        showRedCharge: false,
        selectedRoom: {},
        showPointRule: false,
        selectedRule: {},
        showItem: false,
        selectedItem: {},

        selectedRedMoney: 0,
        clientid: "<%=client._id%>",
      };
    },

    created: function () {
      if (!this.clientid) {
        setTimeout(function () {
          location.reload()
        }, 2000)
      }
      this.getClient();
      this.refreshRooms();
      this.refreshItems();
      this.refreshDraws();
    },
    filters: {
      timestr: function (d) {
        return dayjs(d).format("YYYY-MM-DD HH:mm")
      }
    },
    methods: {
      getClient: function () {
        var that = this;
        axios.get("/client/info").then(function (res) {
          that.client = res.data.client;
          if (!res.data.client) {
            location.reload();
          }
          console.log(that.client)
        });
      },
      refreshRooms: function () {
        let that = this;
        axios.get("/client/rooms").then(function (res) {
          that.rooms = res.data.rooms;
        });
      },
      refreshItems: function () {
        let that = this;

        axios.get("/client/point/items").then(function (res) {
          that.items = res.data.items;
        });
      },
      refreshDraws: function () {
        let that = this;

        axios.get("/client/point/draws").then(function (res) {
          that.draws = res.data.draws;
        });
      },
      chargeRoom: function () {
        let that = this;
        axios
          .post("/client/room/charge", {
            room: that.selectedRoom,
          })
          .then(function (res) {
            let payment = res.data;
            WeixinJSBridge.invoke("getBrandWCPayRequest", payment, function (res) {
              if (res.err_msg == "get_brand_wcpay_request:ok") {
                weui.toast("充值成功", { duration: 500 });
                that.showCharge = false;
                setTimeout(function () {
                  that.refreshRooms();
                }, 2000);
              }
            });
          });
      },

      tryRoom: function () {
        let that = this;
        axios
          .post("/client/room/try", {
            room: that.selectedRoom,
          })
          .then(function (res) {
            if (res.data.status) {
              weui.toast("开通成功", { duration: 500 });
              that.showCharge = false;
              that.refreshRooms();
              that.getClient();
            } else {
              weui.topTips(res.data.msg);
            }
          });
      },
      redeemRoom: function () {
        let that = this;
        axios
          .post("/client/room/redeem", {
            room: that.selectedRoom,
            code: that.selectedRedeemCode,
          })
          .then(function (res) {
            if (res.data.status) {
              weui.toast("开通成功", { duration: 500 });
              that.showCharge = false;
              that.showRedeem = false;
              that.refreshRooms();
              that.getClient();
            } else {
              weui.topTips(res.data.msg);
            }
          });
      },
      removeRoom: function (room) {
        let that = this;
        weui.confirm(
          "确认手动删除群聊, 不再管理此群",
          function () {
            axios
              .post("/client/room/remove", {
                room: room,
              })
              .then(function (res) {
                that.showCharge = false;
                that.refreshRooms();
              });
          },
          function () { },
          { title: room.topic }
        );
      },
      chargeRed: function () {
        if (this.selectedRedMoney <= 0) {
          return weui.topTips("输入红包金额有误");
        }
        let that = this;
        axios
          .post("/client/red/charge", {
            money: that.selectedRedMoney,
          })
          .then(function (res) {
            let payment = res.data;
            WeixinJSBridge.invoke("getBrandWCPayRequest", payment, function (res) {
              if (res.err_msg == "get_brand_wcpay_request:ok") {
                weui.toast("充值成功", { duration: 500 });
                that.showRedCharge = false;
                setTimeout(function () {
                  that.getClient();
                }, 2000);
              }
            });
          });
      },
      openRedeem: function (room) {
        this.showRedeem = true;
        this.selectedRoom = room;
        this.showCharge = false;
      },
      openCharge: function (room) {
        this.selectedRoom = room;
        this.showCharge = true;
      },
      openPointRule: function (room) {
        this.showPointRule = true;
        this.selectedRule = room.pointRule
          ? room.pointRule
          : {
            invite_status: 0,
            invite_point: 1,
            sign_status: 0,
            sign_point: 1,
            roomid: room.id,
            sign_word: "签到",
          };
      },
      submitPointRule: function () {
        let that = this;
        if (this.selectedRule.sign_word && this.selectedRule.sign_word.length > 5) {
          return weui.topTips("签到文字太长, 不要超过五个字");
        }
        axios.post("/client/room/point/rule", this.selectedRule).then(function (res) {
          weui.toast("保存成功", { duration: 500 });
          that.showPointRule = false;
          that.refreshRooms();
        });
      },

      setHome: function (type) {
        // weui.toast("功能更新中", 500);
        // return;
        let that = this;
        let list = [];
        if (type == "mall") {
          return axios
            .post("/client/setHome", {
              label: "积分商城",
              value: false,
            })
            .then(function () {
              weui.toast("设置成功", { duration: 500 });
              that.getClient();
            });
        }

        if (type == "draw") {
          return axios
            .post("/client/setHome", {
              label: "积分抽奖",
              value: false,
            })
            .then(function () {
              weui.toast("设置成功", { duration: 500 });
              that.getClient();
            });
        }

        this.items.forEach((item) => {
          if (item.type == "red") {
            list.push({ label: item.name, value: item._id });
          }
        });

        if (list.length == 1) {
          return axios.post("/client/setHome", list[0]).then(function () {
            weui.toast("设置成功", { duration: 500 });
            that.getClient();
          });
        }
        if (list.length == 0) {
          return (location.href = "/client/page/item");
        }

        weui.picker(list, {
          onConfirm: (result) => {
            axios.post("/client/setHome", result[0]).then(function () {
              weui.toast("设置成功", { duration: 500 });
              that.getClient();
            });
          },
        });
      },
    },
  });
</script>
</div>